# -*- coding: utf-8 -*-
# from lxml import etree as ET
import re
import datetime
from openpyxl import load_workbook
import os
import getpath
import logging


def yearbeforeday(d):
    try:
        d1 = datetime.datetime(d.year + 1, d.month, d.day)
        d1 = d1 + datetime.timedelta(-1)
    except ValueError as e:
        d1 = datetime.datetime(d.year + 1, d.month, d.day - 1)
        d1 = d1 + datetime.timedelta(-1)
    return d1


def set_cell(table, row, col, value):
    print(row, col, value)
    table.cell(row=row, column=col, value=value)


def get_cell(table, row, col):
    return table.cell(row=row, column=col).value


def gen_jiao_zhun(fn):
    xl_book = load_workbook(filename=fn)
    ffbh = getSheet(xl_book, 2)
    syy = getSheet(xl_book, 3)
    ysry = getSheet(xl_book, 4)
    yqbh = getSheet(xl_book, 5)
    return (ffbh, syy, ysry, yqbh)


def getSheet(xlBook, at):
    ffbh = []
    table = xlBook.worksheets[at]
    rows = table.rows
    for row in rows:
        cell = row[0]
        ffbh.append(cell.value)
    return ffbh


def getData():
    fullfilepath = os.path.join(getpath.getpath(), "ffbh.xlsx")
    logging.info(fullfilepath)
    data = gen_jiao_zhun(fullfilepath)
    return data


if __name__ == "__main__":
    print(getData())
